package com.example.callcenter.controller;

import com.example.callcenter.dto.CustomerDTO;
import com.example.callcenter.service.CustomerService;
import com.example.callcenter.util.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/customer")
public class CustomerController {

    @Autowired
    private CustomerService customerService;

    @PostMapping("/add")
    public ResultUtil addCustomer(@RequestBody CustomerDTO customerDTO) {
        customerService.addCustomer(customerDTO);
        return ResultUtil.success("添加成功");
    }

    @GetMapping("/list")
    public ResultUtil getCustomerList() {
        return ResultUtil.success(customerService.list());
    }

    @PostMapping("/batch-import")
    public ResultUtil batchImport(@RequestParam("file") MultipartFile file) {
        int count = customerService.importExcel(file);
        return ResultUtil.success("导入成功：" + count + "条");
    }
}